﻿using DXApplicationTangche.service;
using DXApplicationTangche.UC.标签打印;
using DXApplicationTangche.UC.标签打印.Service;
using DXApplicationTangche.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.订单一览新.销售确认单
{
    public partial class Form客户套号顺丰发运预览 : DevExpress.XtraEditors.XtraForm
    {
        private List<CustomerTagRecordDTO> customerTagRecordDTOs = new List<CustomerTagRecordDTO>();
        public Form客户套号顺丰发运预览(List<CustomerTagRecordDTO> customerTagRecordDTOs)
        {
            InitializeComponent();
            this.customerTagRecordDTOs = customerTagRecordDTOs;
            this.gridControl待发运记录.DataSource = this.customerTagRecordDTOs;
            this.gridView待发运记录.RefreshData();
        }

        private void simpleButton发运_Click(object sender, EventArgs e)
        {
            try
            {
                SfExpressMessageResult sfExpressMessageResult = new SfExpressMessageResult();
                if (this.checkBox是否两联.Checked)
                {
                    sfExpressMessageResult = 发运Service.sfExpressCustomerTagOrder(2, this.customerTagRecordDTOs);
                }
                else
                {
                    sfExpressMessageResult = 发运Service.sfExpressCustomerTagOrder(3, this.customerTagRecordDTOs);
                }
                if (("200").Equals(sfExpressMessageResult.errorCode))
                {
                    FileUtil.DownloadPicture(
                            "http://192.168.3.33:4545/sfexpress/" + customerTagRecordDTOs[0].barcode + "_" + customerTagRecordDTOs[0].mobile + ".jpg",
                            @"pic\" + customerTagRecordDTOs[0].barcode + "_" + customerTagRecordDTOs[0].mobile + ".jpg", -1
                        );
                    System.Diagnostics.Process.Start(@"pic\" + customerTagRecordDTOs[0].barcode + "_" + customerTagRecordDTOs[0].mobile + ".jpg");
                }
                else
                {
                    MessageBox.Show(sfExpressMessageResult.errorMessage);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void gridView待发运记录_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn尺码"))
            {
                if (!String.IsNullOrWhiteSpace(e.DisplayText))
                {
                    try { e.DisplayText = e.DisplayText.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                }
            }
        }
    }
}
